package com.demo;

import org.apache.commons.io.FileUtils;
import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.*;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Test {
    public static void main(String[] args) throws Exception{

        UserVo user = new UserVo();
        user.setName("张三");
        user.setEmail("aaaa@11.com");
        user.setList(Arrays.asList("a","b","c"));
        String content = FileUtils.readFileToString(new File("/Users/wjh/workspace/wjh/demo/dome-parent/demo-beetl/hello.txt"));

        Map<String,String> map = new HashMap<>();
        map.put("val","value");

        //初始化代码
        StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader();
        Configuration cfg = Configuration.defaultConfiguration();
        GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
        //获取模板
        Template t = gt.getTemplate(content);
        t.binding("user", user);
        t.binding(map);
        //渲染结果
        String str = t.render();
        System.out.println(str);

    }
}
